﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Net;
using System.Net.Mail;

public partial class Employee_ChangeStatusApplicant : System.Web.UI.Page
{
    EmployeeMethord EM = new EmployeeMethord();
    string ApplicantID = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            ApplicantID = Request.QueryString["ID"].ToString();
            if (txtJobID.Text.Equals(""))
            {
                LoadInformationApplicant(ApplicantID);
            }
        }
        catch (Exception ex)
        {
            Console.Write(ex.Message);
        }
        btnSave.Enabled = false;
    }
    public void LoadInformationApplicant(string _ApplicantID)
    {
        DataTable tb = EM.ReturnInformationApplicent(_ApplicantID);
        if (tb.Rows.Count > 0)
        {
            SqlDataReader dr = EM.ReturnVacancyName(tb.Rows[0]["VacancyID"].ToString());
            ddlTitleVacancy.DataSource = dr;
            ddlTitleVacancy.DataTextField = "Title";
            ddlTitleVacancy.DataValueField = "VacancyID";
            ddlTitleVacancy.DataBind();
            EM.connClose();
            txtUserName.Text = tb.Rows[0]["FullName"].ToString();
            txtJobID.Text = tb.Rows[0]["ApplicantID"].ToString();
            txtDescription.Text = tb.Rows[0]["Address"].ToString();
            txtPhone.Text = tb.Rows[0]["Phone"].ToString();
            txtBirthOfDate.Text = tb.Rows[0]["BirthOfDate"].ToString();
            txtEmail.Text = tb.Rows[0]["EmailID"].ToString();
            txtEducation.Text = tb.Rows[0]["Education"].ToString();
            txtLanguages.Text = tb.Rows[0]["ForeignLanguages"].ToString();
            txtExpereignce.Text = tb.Rows[0]["WorkExperience"].ToString();
            switch (Convert.ToInt32(tb.Rows[0]["Status"].ToString()))
            {
                case 3:
                    ddlStatus.SelectedIndex = 0;
                    break;
                case 4:
                    ddlStatus.SelectedIndex = 1;
                    break;
                default:
                    if (Convert.ToInt32(tb.Rows[0]["Status"].ToString()) == 1)
                    {
                        ddlStatus.Items.Clear();
                        ddlStatus.Items.Add("Hired");
                    }
                    else if (Convert.ToInt32(tb.Rows[0]["Status"].ToString()) == 2)
                    {
                        ddlStatus.Items.Clear();
                        ddlStatus.Items.Add("Interview");
                    }
                    else
                    {
                        ddlStatus.Items.Clear();
                        ddlStatus.Items.Add("Applicant is not apply to vacancy");
                    }
                    ddlStatus.Enabled = false;
                    btnSave.Visible = false;
                    break;
            }
        }
    }
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        lblSuccess.Text = "";
        lblError.Text = "";
        bool check = EM.UpdateStatusApplicant(txtJobID.Text, Convert.ToInt32(ddlStatus.SelectedItem.Value));
        if (check)
        {
            lblSuccess.Text = "Changed the status of ApplicantID to " + ddlStatus.SelectedItem.Text;
        }
        else
        {
            lblError.Text = "Process failed to change the status";
        }
    }
    protected void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
    {
        btnSave.Enabled = true;
    }
}